var $table = $('#table'), $button = $('#button');
$(function() {
	$table = $('#table').bootstrapTable({
			url : RS.webPath + '/admin/task/doApplyList',
			type : 'post',
			dataType : 'json',
			pagination : true, // 是否显示分页（*）
			sidePagination : 'server', // 分页方式：client客户端分页，server服务端分页（*）
			responseHandler : function(res) {
				return res;
			},
			striped : true, // 是否显示行间隔色
			queryParams : function(params) {
				var searchData = RS.getFormJsonString('searchForm');
				var temp = {
						__limit__ : params.limit, // 页面大小
						__offset__ : params.offset, // 页码
						__data__ : searchData
				};
				return '__paramSet__=' + JSON.stringify(temp);
			},// 传递参数（*）
			onPageChange : function(number, size) {
			}
	});
});
function query() {
	$table.bootstrapTable("refresh");
}
function add() {
	window.location.href = RS.webPath + '/admin/rsActivitiExt/edit?method=INSERT';
}
function del() {
	parent.layer.confirm("是否要删除选中的项目？", {
			icon : 3,
			title : '提示',
	}, function(index) {
		var selections = $table.bootstrapTable("getAllSelections");
		if (selections.length < 1) {
			parent.layer.alert("您未选择任何一条记录");
			return;
		}
		var ids = [];
		for (var i = 0; i < selections.length; i++) {
			ids[i] = selections[i].id
		}
		$.ajax({
				url : RS.webPath + '/admin/rsActivitiExt/del',
				type : 'post',
				dataType : 'json',
				data : '__paramSet__=' + JSON.stringify(ids),
				success : function(ret) {
					if (ret.status == 0) {
						parent.layer.alert('删除失败');
					} else {
						parent.layer.alert('删除成功');
					}
					$table.bootstrapTable("refresh");
				},
				error : function() {
					parent.layer.alert('删除失败');
					$table.bootstrapTable("refresh");
				}
		});
	});
}
function edit() {
	var selections = $table.bootstrapTable("getAllSelections");
	if (selections.length != 1) {
		parent.layer.alert("只能选择一个项目进行编辑");
		return;
	}
	var id = selections[0].id;
	window.location.href = RS.webPath + '/admin/rsActivitiExt/edit?method=UPDATE&id=' + id;
}

function design() {
	var selections = $table.bootstrapTable("getAllSelections");
	if (selections.length != 1) {
		parent.layer.alert("只能选择一个项目进行绘制");
		return;
	}
	var id = selections[0].id;
	window.location.href = RS.webPath + '/templates/admin/activitiDesign/modeler.html?modelId='
			+ id;

}

function pubProcess() {
	var selections = $table.bootstrapTable("getAllSelections");
	if (selections.length != 1) {
		parent.layer.alert("只能选择一个项目进行绘制");
		return;
	}
	var id = selections[0].id;
	var name = selections[0].name;
	$.ajax({
			url : RS.webPath + '/admin/rsActivitiExt/PubProcess',
			type : 'post',
			dataType : 'json',
			data : "id=" + id + "&name=" + name,
			success : function(ret) {
				if (ret.status == 0) {
					parent.layer.alert('发布失败');
				} else if (ret.status > 0) {
					parent.layer.alert('发布成功');
				} else {
					parent.layer.alert('发布失败');
				}
				$table.bootstrapTable("refresh");
			},
			error : function() {
				parent.layer.alert('发布失败');
				$table.bootstrapTable("refresh");
			}
	});
}

function isPublic(val) {
	if (0 == val || "null" == val || undefined == val) {
		return "未发布";
	} else {
		return "已发布，版本号" + val;
	}
}

